package com.guang.future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.*;

/**
 * @author lg
 * @Description
 * @date 2022/11/1 17:44
 */
public class FutureGetTest {
    private static Logger logger = LoggerFactory.getLogger(FutureGetTest.class);
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        Future<String> submit = executorService.submit(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "success";
        });
        try {
            String s = submit.get();
            logger.info("最终的结果是：{}",s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
